package com.coffeeloversupportlibrary.coffeelover.domain.article.adapter;

import android.content.Intent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.coffeeloversupportlibrary.coffeelover.contentshow.Details;
import com.coffeeloversupportlibrary.coffeelover.domain.article.entity.Article;
import com.youth.banner.adapter.BannerAdapter;

import java.util.List;

/**
 * @author puyv
 * @createTime 2021/11/6 20:24
 * @projectName CoffeeLoverSupportLibrary
 * @className ImageAdapter.java
 * @description TODO
 */
public class SlideshowListAdapter extends BannerAdapter<Article,SlideshowListAdapter.BannerViewHolder> {


    public SlideshowListAdapter(List<Article> articles) {
        super(articles);
    }

    @Override
    public BannerViewHolder onCreateHolder(ViewGroup parent, int viewType) {
        ImageView imageView = new ImageView(parent.getContext());
        imageView.setLayoutParams(new ViewGroup.LayoutParams(
                ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT));
        imageView.setScaleType(ImageView.ScaleType.FIT_XY);
        return new BannerViewHolder(imageView);

    }

    @Override
    public void onBindView(BannerViewHolder holder, Article data, int position, int size) {
       //原始：
//        holder.imageView.setImageResource(data.getImageTest());

        Glide.with(holder.imageView.getContext())
                .load(data.getArticleBanner())
                .into(holder.imageView);

        // 点击文章的逻辑
        holder.imageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(holder.itemView.getContext(), Details.class);
                intent.putExtra("articleId",data.getArticleId());
                intent.putExtra("title",data.getArticleTitle());
                holder.itemView.getContext().startActivity(intent);
            }
        });
    }

    static class BannerViewHolder extends RecyclerView.ViewHolder {
        ImageView imageView;
        public BannerViewHolder(@NonNull ImageView view) {
             super(view);
             this.imageView = view;
        }
    }
}


